Func _Map_OpenMap ($sFile = "Data.dat")
	_Write ("_Map_OpenMap (" & $sFile & ")")
	$sFile = "Map_Cache\" & $sFile
	$sName = FileReadLine($sFile, 1)
	_Write ("Loading map : " & $sName)
	$iLine = 1

	$sSizeData = FileReadLine($sFile, 5)
	$aSizeData = StringSplit($sSizeData, "*")
	If @error = 1 Then
		_Write ("Wrong map formation. ( aSizeData is no Array )")
		Exit
	EndIf

	$iMapW = $aSizeData[1]
	$iMapH = $aSizeData[2]

	_GDIPlus_GraphicsDrawImage($hGraphics, $hWallpaperImage, 0, 0)
	_GDIPlus_GraphicsFillRect($hGraphics, 200, 200, 400, 200, $hButtonBrush)
	_GDIplus_GraphicsDrawString($hGraphics, "Loading map...", 295, 265)
	_GDIPlus_GraphicsDrawRect($hGraphics, 200, 200, 400, 200)
	For $i = 0 To $iMapH - 1
		For $a = 0 To $iMapW - 1
			_Map_DrawFieldToBuffer(FileReadLine("Map_Cache\map.wws", $iLine), $a, $i)
			$iLine += 1
		Next
		$iLine += 1
	Next
EndFunc

Func _Map_DrawFieldToBuffer($sParams, $iX, $iY)
	If Not IsDeclared("hMapBuffer") Then
		_Write ("$hMapBuffer is not deklared! Fatal error.", 1)
		_Exit ("Graphics error")
	Endif
	_Write ("_Map_DrawFieldToBuffer(" & $sParams & "," & $iX & "," & $iY & ")",Default)
	If $sParams = "" Then _Write ("Error in map format!", 1)
	$aParams = StringSplit($sParams, ",")
;~ 	_GDIPlus_GraphicsDrawString($hMapBuffer, ".", $iX * 30, $iY * 30)
	Switch $aParams[1]
		Case 0;Grass
			_GDIPlus_GraphicsDrawImageRectRect($hMapBuffer, $hGroundImage,  _Map_GetTilePos(3), _Map_GetTilePos (3), $MAP_W, $MAP_H, $iX * 30, $iY * 30, 30, 30)
		Case 1;Bush
			_GDIPlus_GraphicsDrawImageRectRect($hMapBuffer, $hGroundImage, _Map_GetTilePos(2), _Map_GetTilePos (1), $MAP_W, $MAP_H, $iX * 30, $iY * 30, 30, 30)
	EndSwitch
	If @error Then _Write (@error)
EndFunc

Func _Map_GetTilePos ($iCoord)
	$iReturn = 0
	For $i = 0 To $iCoord - 1
		$iReturn += $MAP_H + 1
	Next
	Return $iReturn
EndFunc

Func _Map_DrawMap ()
;~ 	_GDIPlus_GraphicsDrawString($hMapBuffer, "Test", 0, 0)
	If Not IsDeclared("hMapBitmap") Then
		_Write ("$hMapBitmap is not deklared! Fatal error.", 1)
		_Exit ("Graphics error")
	Endif
	$bResult = _GDIPlus_GraphicsDrawImageRect($hBuffer, $hMapBitmap, 0, 0, 600, 600)
	If Not $bResult Then
		_Write ("Error at _Map_DrawMap ()", 1)
		SetError(1);cant draw on buffer (perhaps theres no buffer ?)
	EndIf
EndFunc